package com.digdes.calendar.gwt.client.widget;

import com.digdes.calendar.gwt.client.dto.EventDTOImpl;
import com.google.gwt.user.client.ui.*;

import java.util.List;

public class EventsPanel extends Composite {

    private VerticalPanel vp = new VerticalPanel();
    private Label labelDate = new Label();

    public EventsPanel() {
        ScrollPanel scrollPanel = new ScrollPanel(vp);
        scrollPanel.setSize("232px", "355px");
        labelDate.setStyleName("labelDate");
        VerticalPanel vpMain = new VerticalPanel();
        vpMain.add(labelDate);
        vpMain.add(scrollPanel);
        setWidget(vpMain);
    }

    public void setLabelDate(String s) {
        labelDate.setText(s);
    }

    public void addEvent(FlexTable table) {
        vp.add(table);
    }

    public VerticalPanel getVp() {
        return vp;
    }

    public void setData(int selectDay, int selectMonth, int selectYear, List<EventDTOImpl> eventDTOList) {
        String sLabelDate = selectDay + " " + Data.OTHER_MONTH[selectMonth]
                + " " + selectYear;
        FlexTable eventsTable = new FlexTable();
        int iRow = 0;
        getVp().clear();
        setLabelDate(sLabelDate);
        for (EventDTOImpl eventDTO : eventDTOList) {

            eventsTable.setText(iRow, 0, eventDTO.getNameEvent());
            eventsTable.getCellFormatter().setStyleName(iRow, 0, "nameEventLbl");
            iRow++;
            if (eventDTO.getMyPlace() != null) {
                eventsTable.setText(iRow, 0, "Место проведения: "
                        + eventDTO.getMyPlace());
            } else if (eventDTO.getPlace() != null) {
                eventsTable.setText(iRow, 0, "Место проведения: "
                        + eventDTO.getPlace().getAddress());
            }
            eventsTable.getCellFormatter().setStyleName(iRow, 0, "placeLbl");
            iRow++;

            eventsTable.setCellPadding(0);
            eventsTable.setCellSpacing(0);
            addEvent(eventsTable);
        }
    }
}